package acwing._2LanQiao._12No12;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._2LanQiao._12No12
 * @File : Q3422.java
 * @Author : WangRuoyu
 * @Date : 2023/3/30 11:04
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Q3422 {
    static int[] childNums;
    static int[] tree;
    static int[] f;
    static int n;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");
        n = Integer.parseInt(words[0]);
        childNums = new int[n + 1];
        tree = new int[n + 1];
        f = new int[n + 1];
        for (int i = 2; i <= n; ++i) {
            words = br.readLine().split(" ");
            int father = Integer.parseInt(words[0]);
            tree[i] = father;
            childNums[father] += 1;
        }

        int res = 0;
        for (int i = 2; i <= n; ++i) {
            f[i] = f[tree[i]] + childNums[tree[i]];
            res = Math.max(res, f[i]);
        }

        System.out.println(res);

    }
}